﻿﻿using System;
using System.Collections;
using System.Collections.Generic;

using UnityEngine;

namespace ALPackage
{
    /*********************
     * UI系统层级管理对象的每个UI层级的根节点对象
     **/
    public class ALUILayerRootNode : _AALUILayerBasicDynamicNode
    {
        private Canvas _m_coCanvasObj;
        /// <summary>
        /// 对应的系统相关层级属性值
        /// </summary>
        private int _m_iSortingLayerId;
        private int _m_iOrderInLayer;

        public ALUILayerRootNode(ALUILayerInfo _layerInfo)
            : base(new ALUILayerNodeCanvasObj(_layerInfo.cavasObj))
        {
            if(null == _layerInfo)
                return;

            _m_coCanvasObj = _layerInfo.cavasObj;
            if(null != _m_coCanvasObj)
            {
                _m_iSortingLayerId = _m_coCanvasObj.sortingLayerID;
                _m_iOrderInLayer = _m_coCanvasObj.sortingOrder;

                _setOrderInLayer(_m_iSortingLayerId, _m_iOrderInLayer);
            }
        }

        /// <summary>
        /// 当前所在层级
        /// </summary>
        public override int sortingLayerId { get { return _m_iSortingLayerId; } }
        /// <summary>
        /// 当前所在层级
        /// </summary>
        public override int orderInLayer { get { return _m_iOrderInLayer; } }
        /// <summary>
        /// 相对父节点的层级对比
        /// </summary>
        public override int orderLayerToParentNode { get { return 0; } }


        /// <summary>
        /// 设置当前的层级信息
        /// </summary>
        /// <param name="_layer"></param>
        protected override void _setOrderInLayer(int _sortingLayer, int _layer)
        {
            //设置层级
            _m_coCanvasObj.sortingLayerID = _sortingLayer;
            _m_coCanvasObj.sortingOrder = _layer;
        }

        /// <summary>
        /// 当修改当前层级的时候，触发的函数
        /// </summary>
        /// <param name="_orderLayerToParentNode"></param>
        protected override void _onSetNewLayer(int _orderLayerToParentNode, int _finalLayer)
        {
        }

        /// <summary>
        /// 子类的资源释放处理函数
        /// </summary>
        protected override void _doDiscard()
        {

        }
    }
}
